﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpMUD.Framework.ComponentModel;
using SharpMUD.Framework.Workflow.Generic;

namespace SharpMUD.Framework.Services.CodeDomAwareness
{
    public partial class CodeDomAwarenessService
        : IService, IHasExecutionStatus
    {
        #region IService Members

        public IServicesHost ServicesHost
        {
            get;
            private set;
        }

        public void Initialize(IServicesHost servicesHost)
        {
            if (this.ExecutionStatus != ExecutionStatusTokens.UnInitialized)
                throw new InvalidExecutionStatusTransitionException(this.ExecutionStatus, ExecutionStatusTokens.Initializing);
            this.ExecutionStatus = ExecutionStatusTokens.Initializing;
            log.Info(this.ExecutionStatus.ToString());

            this.IsInitialized = true;
            this.ExecutionStatus = ExecutionStatusTokens.Initialized;
            log.Info(this.ExecutionStatus.ToString());
        }

        public bool IsInitialized
        {
            get;
            private set;
        }

        #endregion

        public event EventHandler<ValueChangedEventArgs<IExecutionStatusToken>> ExecutionStatusChanged;

        private IExecutionStatusToken _ExecutionStatus;
        public IExecutionStatusToken ExecutionStatus
        {
            get
            {
                return _ExecutionStatus;
            }
            private set
            {
                IExecutionStatusToken oldValue = _ExecutionStatus;
                if (oldValue != value)
                {
                    _ExecutionStatus = value;
                    if (ExecutionStatusChanged != null)
                        ExecutionStatusChanged(this, new ValueChangedEventArgs<IExecutionStatusToken>(oldValue, value));
                }
            }
        }
    }
}